package com.zhu.SupermarketInventoryManagement.controller;


import com.zhu.SupermarketInventoryManagement.model.QO.AdminQO;
import com.zhu.SupermarketInventoryManagement.model.ResultCommon;
import com.zhu.SupermarketInventoryManagement.service.LoginService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/admin/api")
public class LoginApiController {

    @Resource
    LoginService loginService;

    //登录
    @PostMapping("/login")
    public ResultCommon<Object> login(@RequestBody AdminQO adminQO) {
        return loginService.login(adminQO);
    }

    @PostMapping("/logout")
    public ResultCommon<Object> login(HttpSession session) {
        ResultCommon<Object> resultCommon=new ResultCommon<>();
        session.removeAttribute("admin");
        resultCommon.setCode(0);
        return resultCommon;
    }

}
